package com.letv.app.ljodfh.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.ui.widget.TextViewExpandableAnimation;
import com.letv.app.ljodfh.R;
import com.letv.app.ljodfh.beans.FComment;
import com.letv.app.ljodfh.ui.utils.GlideCircleTransform;
import com.letv.app.ljodfh.ui.utils.GlideUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/24 0024.
 */

public class CommentHolder extends BaseAbsHolder<FComment> {
    @BindView(R.id.item_topic_detail_comment_icon)
    protected CustomEXImageView img;
    @BindView(R.id.item_topic_detail_comment_username)
    protected CustomFontTextView username;
    @BindView(R.id.item_topic_detail_comment_time)
    protected CustomFontTextView time;
    @BindView(R.id.item_topic_detail_comment_comment)
    protected CustomFontTextView content;
    @BindView(R.id.item_topic_detail_comment_reply)
    protected CustomFontTextView reply;
    @BindView(R.id.item_topic_detail_comment_divider)
    protected View divider;
    private FComment comment;
    private List<FComment> list;

    private FComment fComment;

    public CommentHolder(Context context, View itemView, List<FComment> list) {
        super(context, itemView);
        this.list = list;
//        content.setOnStateChangeSetting(new TextViewExpandableAnimation.OnStateChangeSetting() {
//            @Override
//            public void reInitStateView(TextView stateView) {
////                stateView.setBackgroundResource(R.drawable.bg_comment_all_l);
//                stateView.setText(R.string.newes_see_all);
////                ViewGroup.MarginLayoutParams mlp= (ViewGroup.MarginLayoutParams) stateView.getLayoutParams();
////                mlp.topMargin= DensityUtil.dip2px(context,18);
////                stateView.setLayoutParams(mlp);
//            }
//            @Override
//            public void onStateChanged(TextView stateView, boolean isShrink) {
//                JLog.e(" is shrink=" + isShrink + "   " + this);
//                content.getStateImg().setRotation(isShrink ? 90 : -90);
//            }
//        });
//        content.setOnStateChangeListener(new TextViewExpandableAnimation.OnStateChangeListener() {
//            @Override
//            public void onStateChange(boolean isShrink) {
//                if (fComment != null) {
//                    fComment.setShrink(isShrink);
//                }
//            }
//        });
//        content.resetState(true);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FComment comment) {
//        if (getAdapterPosition() == list.size() - 1) {
//            divider.setVisibility(View.GONE);
//        } else {
//            divider.setVisibility(View.VISIBLE);
//        }
        this.comment = comment;
        if (TextUtils.isEmpty(comment.getAnswerTo())) {
            username.setText(comment.getNickName());
            reply.setVisibility(View.VISIBLE);
        } else {
            username.setText(comment.getNameSpanned());
            reply.setVisibility(View.GONE);
        }
        time.setText(comment.getPubTime());
        content.setText(comment.getComment());
//        content.resetState(comment.isShrink());
        if (!TextUtils.isEmpty(comment.getAvatar())) {
            GlideUtil.getGlideWithAvatorDef(context, comment.getAvatar()).error(R.mipmap.icon_circle_avatar)
                    .placeholder(R.mipmap.icon_circle_avatar).transform(new GlideCircleTransform(context)).into(img);
        }
    }

    @OnClick(value = {R.id.item_topic_detail_comment_reply})
    public void reply(View view) {
        if (internalClick != null) {
            itemView.setTag(R.id.adapter_item_data_key, comment);
            internalClick.onItemInternalClick(itemView, view, getAdapterPosition());
        }
    }

    @Override
    public CommentHolder setInternalClick(OnItemInternalClick internalClick) {
        super.setInternalClick(internalClick);
        return this;
    }
}
